package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderSettingService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.awt.*;
import java.io.File;
import com.itheima.health.pojo.OrderSetting;
import com.itheima.health.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ordersetting")
public class OrderSettingController {

    @Autowired
    private OrderSettingService orderSettingService;


    @PostMapping("/upload")
    public Result upload(MultipartFile excelFile) {
        orderSettingService.upload(excelFile);
        return new Result(true, MessageConst.UPLOAD_SUCCESS);
    }
    /**
     *
     * @param year,month
     * @return
     * author:MaJun
     */
    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth (String year,String month){//yyyy-MM
        String date = year+"-"+month;
        try {
            List<Map> list  =orderSettingService.getOrderSettingByMonth(date);
            return new Result(true, MessageConst.GET_ORDERSETTING_SUCCESS,list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConst.GET_ORDERSETTING_FAIL);
        }
    }

    /**
     * 根据日期设置预约
     * @param orderSetting
     * @return
     */
    @PostMapping("/editNumberByDate")
    public Result editNumberByDate(@RequestBody OrderSetting orderSetting) {
        try {
            orderSettingService.editNumberByDate(orderSetting);
            return new Result(true,MessageConst.ORDER_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
        return new Result(false,MessageConst.ORDERSETTING_FAIL);
        }
    }
}
